package com.cat.dataStructure02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/next-greater-numerically-balanced-number/?envType=daily-question&envId=2025-10-24
 * @create 2025/10/24 09:04
 * @since JDK17
 */

public class Solution56 {
    static int N = 1224444;
    boolean isBalance(int num) {
        int[] cnt = new int[10];
        while (num != 0) {
            cnt[num % 10]++;
            num /= 10;
        }
        for (int i = 1; i < 10; i++) {
            if (i != cnt[i]) {
                return false;
            }
        }

        return true;
    }

    public int nextBeautifulNumber(int n) {
        for (int i = n + 1; i <= N; i++) {
            if (isBalance(i)) {
                return i;
            }
        }

        return N;
    }
}
